package com.jic.interaction.JDVOP.controller;

import com.jic.interaction.JDVOP.common.utils.RestResult;
import com.jic.interaction.JDVOP.model.entity.*;
import com.jic.interaction.JDVOP.model.vo.request.*;
import com.jic.interaction.JDVOP.service.SiteApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;


@RestController
@RequestMapping("/api/area")
@Api(tags = " [地址API接口]")
public class SiteApiOneController {

    @Resource
    private SiteApiService service;

    /*
        查询京东一级地址列表。
     */

    @ApiOperation(value = "3.1 查询一级地址")
    @PostMapping("/getProvince")
    @ResponseBody
    public RestResult selectOne(@RequestBody SiteApiRequestOne requestOne) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        SiteApiOne one = new SiteApiOne();
        BeanUtils.copyProperties(requestOne,one);
        return  service.selectOne(one);
    }

    /*
        根据京东一级地址ID，查询京东二级地址列表。
     */

    @ApiOperation(value = "3.2 查询二级地址")
    @PostMapping("/getCity")
    @ResponseBody
    public RestResult selectTwo(@RequestBody SiteApiRequestTwo requestTwo) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        SiteApiTwo two = new SiteApiTwo();
        BeanUtils.copyProperties(requestTwo,two);
        return service.selectTwo(two);
    }

    /*
        根据京东二级地址ID，查询京东三级地址列表。
     */

    @ApiOperation(value = "3.3 查询三级地址")
    @PostMapping("/getCounty")
    @ResponseBody
    public RestResult selectThree(@RequestBody SiteApiRequestThree requestThree) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        SiteApiThree three = new SiteApiThree();
        BeanUtils.copyProperties(requestThree,three);
        return service.selectThree(three);
    }

    /*
        根据京东三级地址ID，查询京东四级地址列表。
     */

    @ApiOperation(value = "3.4 查询四级地址")
    @PostMapping("/getTown")
    @ResponseBody
    public RestResult selectFour(@RequestBody SiteApiRequestFour requestFour) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        SiteApiFour four = new SiteApiFour();
        BeanUtils.copyProperties(requestFour,four);
        return service.selectFour(four);
    }

    /*
        验证已编码为京东一至四级地址ID的有效性。
     */

    @ApiOperation(value = "3.5 验证地址有效性")
    @PostMapping("/checkArea")
    @ResponseBody
    public RestResult selectId(@RequestBody VerifiCationIdRequest idRequest) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        VerifiCationId cationId = new VerifiCationId();
        BeanUtils.copyProperties(idRequest,cationId);
        return service.selectId(cationId);
    }

    /*
        根据地址详情转换为京东地址编码。
        该接口不能保证所有地址都匹配到京东地址，
        也不能保证所有匹配到的京东地址都正确。
        因而，优先推荐使用逐级选择的方法。
     */

    @ApiOperation(value = "3.6 地址详情转换京东地址编码")
    @PostMapping("/getJDAddressFromAddress")
    @ResponseBody
    public RestResult selectParticulars(@RequestBody ParticularsTransition transition) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        ParticularsTransition particul = new ParticularsTransition();
        BeanUtils.copyProperties(transition,particul);
        return service.selectParticulars(particul);
    }

}
